package contactbook.test.mock.dao;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.EntityManager;

import contactbook.dao.ContactDAOInterface;
import contactbook.model.Contact;

public class ContactDAOMock implements ContactDAOInterface {

	private Contact contact = null;
	
	@Override
	public Contact addContact(Contact contact) {
		this.contact = new Contact(contact.getFirstName(), contact.getLastName());
		this.contact.setId(1);
		this.contact.setAccount(contact.getAccount());
		this.contact.setGroup(contact.getGroup());
		return this.contact;
	}

	@Override
	public void delete(int contactId) {
		if (contact.getId() == contactId)
			contact = null;
	}

	@Override
	public Contact findById(int contactId) {
		return (contact != null && contact.getId() == contactId) ? contact : null;
	}

	@Override
	public List<Contact> findByName(int ownerId, String firstName, String lastName) {
		if (contact != null && contact.getFirstName() == firstName && contact.getLastName() == lastName) {
			List<Contact> l = new ArrayList<Contact>();
			l.add(contact);
			return l;
		}
		return null;
	}

	@Override
	public void update(Contact contact) {
		this.contact.setFirstName(contact.getFirstName());
		this.contact.setLastName(contact.getLastName());
		this.contact.setGroup(contact.getGroup());
	}

	@Override
	public List<Contact> getContactsWithoutGroup(int ownerId) {
		if (contact != null && contact.getGroup() == null) {
			List<Contact> l = new ArrayList<Contact>();
			l.add(contact);
			return l;
		}
		return null;
	}
	
	@Override
	public void setEntityManager(EntityManager em) {
		// Nothing
	}

}
